package com.heu.blood.send.controller;

import com.heu.blood.common.aop.ControllerLogAnnotation;
import com.heu.blood.common.utils.PageUtils;
import com.heu.blood.common.utils.R;
import com.heu.blood.match.entity.BloodInformationEntity;
import com.heu.blood.send.entity.BloodSendEntity;
import com.heu.blood.send.service.BloodSendService;
import com.heu.blood.send.vo.BloodSendVo;
import com.heu.blood.send.vo.BloodSendWithPatientVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 * 
 *
 * @author lyj
 * @email lyj@heu.com
 * @date 2024-10-09 16:13:46
 */
@RestController
@RequestMapping("send/bloodsend")
public class BloodSendController {
    @Autowired
    private BloodSendService bloodSendService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = bloodSendService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		BloodSendEntity bloodSend = bloodSendService.getById(id);

        return R.ok().put("bloodSend", bloodSend);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody BloodSendEntity bloodSend){
		bloodSendService.save(bloodSend);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody BloodSendEntity bloodSend){
		bloodSendService.updateById(bloodSend);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		bloodSendService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 生成一个发血的记录
     */
    @RequestMapping("/sendBlood")
    @ControllerLogAnnotation(module = "发血模块", operate = "将血液发出")
    public R sendBlood(@RequestBody BloodSendVo bloodSend){
        int flag = bloodSendService.sendBlood(bloodSend);
        return R.ok();
    }

    /**
     * 根据申请单中申请项id来查询所有发血信息
     */
    @RequestMapping("/selectSendBloodWithId")
    @ControllerLogAnnotation(module = "发血模块", operate = "根据申请单中申请项id来查询所有发血信息")
    public R selectSendBloodWithId(@RequestBody BloodSendEntity bloodSend){
        List<BloodSendVo> res = bloodSendService.selectSendBloodWithId(bloodSend);
        return R.ok().put("data",res);
    }

    /**
     * 完成取血，同步更新血液状态，申请单状态以及发血表中信息
     */
    @RequestMapping("/sureGetBlood")
    @ControllerLogAnnotation(module = "发血模块", operate = "完成取血，同步更新血液状态，申请单状态以及发血表中信息")
    public R sureGetBlood(@RequestBody BloodSendVo bloodSend){
        int flag = bloodSendService.sureGetBlood(bloodSend);
        return R.ok();
    }

    /**
     * 根据血液ID查询当前配血人员的相关信息
     */
    @RequestMapping("/selectBloodSendInfoByPatientId")
    @ControllerLogAnnotation(module = "发血模块", operate = "根据血液ID查询当前配血人员的相关信息")
    public R selectBloodSendInfoByPatientId(@RequestBody BloodSendVo bloodSend){
        BloodSendWithPatientVo res = bloodSendService.selectBloodSendInfoByPatientId(bloodSend);
        return R.ok().put("data",res);
    }


}
